home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Turnbull China Bikeride
/
Turnbull China Bikeride - Disc 2.iso
/
ACORNUSERS
/
EMULATOR
/
BABE
/
!Babe
/
asm
(
.txt
)
< prev
next >
Wrap
RISC OS BBC BASIC V Source
|
1998-02-04
|
7KB
|
323 lines
Project Commenced: 13/1/98
log%=1
Assembler(infile$,outfile$)
open file and set up variables
outfile$,
(outfile$)-1,1)<>"."
, logfile$=
outfile$,
(outfile$)-1)+"L"
logfile$=outfile$+"L"
log%=1
logfile=
(logfile$)
log%=1
#logfile,"Logfile of assembly of: "+infile$
log%=1
#logfile,"Saved as: "+outfile$
log%=1
#logfile,version$
log%=1
#logfile,
infile=
(infile$)
)asm_error%=0 :
assembly error found
asm_erl%=0
5asmlines%=0 :
number of lines actually assembled
'object%=0 :
current assembled line
3numval%=0 :
value for NUM instr (for assembly)
- asm$=
#infile :
read line from file
1 count%=1 :
init string position
@ count%=
FindNoneSpace(asm$,count%) :
skip leading spaces
asm$,count%,1))<>-1
asm_erl%+=1 :
if not CR then inc line
G
the next line checks for any CRs which read as a separate line
!J
and comments which should be the 1st thing or last thing on line
"8
asm$,count%,1)<>";"
asm$,count%,1))<>-1
count%<>0
$E storeline$=
asm$,count%,2) :
all storeline are 2 digits
%D
storeline$<>"00"
(storeline$)=0
asm_error%=1:
&D
(storeline$)>31
(storeline$)<0
asm_error%=3:
'9 count%+=2 :
place pointer after line number
*"
get next nonspace char
+; count%=
FindNoneSpace(asm$,count%) :
skip spaces
,?
if none found then only a line store number - error
-'
count%=0
asm_error%=4:
/&
check for comment mid-line
02
asm$,count%,1)=";"
asm_error%=2:
27
Check that not prematurely at end of string
3.
count%>=
(asm$)
asm_error%=5:
5A
Check mnemonic, allowing lower case or mixed case too
6C mnemonic1$=
asm$,count%,3) :
all mnemonics are 3 letters
mnemonic$=""
8)
Convert mnemonic to uppercase
x%=1
:& char=
mnemonic1$,x%,1))
;3
char>90
char-=32 :
make uppercase
mnemonic$+=
(char)
>*
assemble mnemonic -> binary
mnemonic$
@
"JMP" : fn$="000"
A
"JRP" : fn$="100"
B
"LDN" : fn$="010"
C
"STO" : fn$="110"
D
"SUB" : fn$="001"
E<
"SB5" :
asmopt%?0=1
fn$="001"
fn$="101"
F
"CMP" : fn$="011"
G
"STP" : fn$="111"
HF
"NUM" : fn$="XXX" :
put 32 bit signed number on line
I4
: asm_error%=6 :
unrecognised fn
asm_error%=6
LB count%+=3 :
increment position to letter after mnemonic
MG
mnemonic$="STP"
mnemonic$="CMP"
actlreq%=
actlreq%=
O"
get next nonspace char
P; count%=
FindNoneSpace(asm$,count%) :
skip spaces
R1
since STP and CMP requires no actline
actlreq%
T@
only a line store number and mnemonic no act line
U*
count%=0
asm_error%=8:
VE
no comments mid line after mnemonic and before actline
W5
asm$,count%,1)=";"
asm_error%=7:
get actline
countn%=count%
countn%+=1
^# char$=
asm$,countn%,1)
_J
"0123456789 ;"+
13,char$)=0
actlreq%
asm_error%=10
`_
char$=" "
(char$)=10
(char$)=13
char$=";"
countn%>=
(asm$)
asm_error%>0
asm_error%>0
b3 actline$=
asm$,count%,(countn%-count%)+1)
d+
check for out of range actlines
eR
mnemonic$<>"NUM"
(actline$)>31
(actline$)<0)
asm_error%=9:
f]
log%=1
#logfile,"SL: "+storeline$+" FN: "+mnemonic$+" AL: "+actline$+" ";
Assemble code
i< asmlines%+=1 :
inc number of lines assembled
j+ obj$(object%)="00"+storeline$+":"
mnemonic$<>"NUM"
l+ actlineb$=actlin$(
(actline$))
m% obj$(object%)+=actlineb$
n#
actlineb$<>"00000"
o,
mnemonic$="CMP"
Warn(1)
p,
mnemonic$="STP"
Warn(2)
r0 obj$(object%)+=
8,"0")+fn$+
16,"0")
s:
add spare 8 bits, fn and next spare 16 bits
u"
set R1 for assembly
B%=
(actline$)
w$ numval%=
(Reverse32Bit)
xF
"OS_ConvertBinary4",numval%,binstring%,33
,A%:?A%=13
y6 obj$(object%)=obj$(object%)+$(binstring%)
{,
log%=1
#logfile,obj$(object%)
object%+=1
#infile
asm_error%>0
#infile
log%=1
#logfile,"Saving Object code file..."
output assembled file
outfile=
(outfile$)
#outfile,
asmlines% :
for compatiblity with PC!
x%=0
asmlines%-1
#outfile,obj$(x%)
this automatically outputs an extra line just like PC
#outfile
("SETTYPE "+outfile$+" BAB")
asm_error%<>0
display error
asm_error%
'
1 : m$="Invalid storeline"
Q
2 : m$="Cannot have a comment after a storeline but before mnemonic"
J
3 : m$="Store line cannot be greater than 31 or less than 00"
B
4 : m$="Only a line store, no mnemonic, nor act line"
9
5 : m$="Incomplete mnemonic and no act line"
+
6 : m$="Unrecognised mnemonic"
7
7 : m$="Comments are not allowed mid line"
J
8 : m$="All mnemonics except CMP and STP require an act line"
Q
9 : m$="Actlines must be in the range 0-31 except for with a NUM fn"
L
10 : m$="Actlines must be an integer value only using digit 0-9"
log%=1
#logfile,m$+" at line "+
(asm_erl%)+" ptr="+
count%
OSCLI("SPOOL")
log%=1
#logfile,"Assembly complete."
log%=1
#logfile
log%=1
("SETTYPE "+logfile$+" FFF")
data for actline conversion from number 0 to 31
"00000","10000","01000","11000","00100","10100","01100","11100","00010"
"10010","01010","11010","00110","10110","01110","11110","00001","10001"
"01001","11001","00101","10101","01101","11101","00011","10011","01011"
"11011","00111","10111","01111","11111"
Warn(warn%)
warn%
N
1 : w$="CMP instructions shouldn't really have an actline applied"
N
2 : w$="STP instructions shouldn't really have an actline applied"
log%=1
#logfile,"WARNING: "+w$+" at line "+
(asm_erl%)+" ptr="+
count%
FindNoneSpace(asm$,count%)
pass to it string to be checked, and char to start checking from
passes back pos of next non string char
notspace%=
asm$,count%,1)=" "
count%<
(asm$)
count%+=1
asm$,count%,1)=" "
count%=
(asm$)
count%=0
=count%